package com.bah.tract.client;

import java.awt.AWTException;
import java.awt.SystemTray;
import java.awt.TrayIcon;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bah.tract.client.cache.je.WorkCache;
import com.bah.tract.service.TractServiceException_Exception;
import com.google.inject.Guice;
import com.google.inject.Injector;

public final class Main {

	private static final Logger LOG = LoggerFactory.getLogger(Main.class);

	private Main() {

	}

	/**
	 * @param args
	 * @throws TractServiceException_Exception
	 */
	public static void main(final String[] args)
			throws TractServiceException_Exception {

		System.setProperty(
				"com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump",
				"false");

		System.setProperty("javax.net.ssl.trustStore",
				"c:/projects/tract/trustStore.jks");

		final Injector injector = Guice.createInjector(new ClientModule());
		final TrayIcon trayIcon = injector.getInstance(TrayIcon.class);
		final WorkCache workCache = injector.getInstance(WorkCache.class);
		final Timer timer = injector.getInstance(Timer.class);
		if (workCache.get("current") != null) {
			timer.setState(true);
		} else if (workCache.get("last") != null) {
			timer.setState(false);
		}
		final SystemTray tray = SystemTray.getSystemTray();
		try {
			tray.add(trayIcon);
		} catch (final AWTException e) {
			LOG.error("TrayIcon could not be added.");
		}
	}
}
